#include "Day.h"


// default CTOR
Day::Day()
{
}

//CTOR
Day::Day(const string& day)
{
	dayOfWeek = day;
}
// add meeting to day
void Day::addMeetingToDay(Meeting* meet)
{
	vector<Meeting*>::iterator it;
	it=dayMeeting.begin();
	while ((it < dayMeeting.end()) && ((((**it).getStartHour() <(*meet).getStartHour())) || 
		(((**it).getStartHour() == (*meet).getStartHour()) && ((**it).getStartMinute() < (*meet).getStartMinute()))))
	{
		it++;
	}
	dayMeeting.insert(it,meet);
}

//delete meeting from day
void Day::deleteMeetingFromDay(int startHour, int startMinute)
{
	int i = findMeetingInDay(startHour,startMinute);
    delete (dayMeeting[i]);
	dayMeeting.erase(dayMeeting.begin()+i);
}

//find meeting in day that start in specific time 
int Day::findMeetingInDay(int startHour, int startMinute)const
{

	vector<Meeting*>::const_iterator it;
	int temp = -1;
    for ( it=dayMeeting.begin() ; it < dayMeeting.end(); it++ )
	{
		temp++;
		if(((**it).getStartHour() == startHour)&& ((**it).getStartMinute() == startMinute))
		{
			return (temp);
		}
	}
	return temp;
}



//print out meeting in place i
void Day::printOut(int i)const
{
	(*dayMeeting[i]).printOut();
}

//remove meeting from day without delete it
Meeting* Day::removeMeetingFromDay(int startHour, int startMinute)
{
	Meeting * temp;
	int i = findMeetingInDay(startHour,startMinute);
	temp = dayMeeting[i];
	dayMeeting.erase(dayMeeting.begin()+i);
	return temp;
}

//get the vector of meeting
const vector<Meeting*>& Day::getVec ()const
{
	return dayMeeting;
}

//delete all meeting from day
void Day::deleteAll()
{
	vector<Meeting*>::iterator it;
    for (it=dayMeeting.begin() ; it < dayMeeting.end(); it++)
	{
		delete(*it);

	}
	dayMeeting.clear();
}
//printout
void Day::printOut()const
{
	cout << setfill(' ');
	if(dayMeeting.size() == 0)
	{
		cout << "No meetings at " << dayOfWeek << endl;
		return;
	}

	for (int i=0; i<76; i++)
		cout << "-";

	cout << "" << endl;
	cout << "| " << setw(12) << left << dayOfWeek << "| "  
		<< setw(19) << "Subjet" << "| " 
		<< setw(10) << "Type" << "| "
		<< setw(26) << "Participators" << "| " << endl;
	for (int i=0; i<76; i++)
		cout << "-";
	cout << endl;
	for (int i=0; i<76; i++)
		cout << "-";
	cout << endl;
	for(int i = 0;i<(int)dayMeeting.size();i++)
	{
			(*dayMeeting[i]).printOut();
	}
}

//check intersection (return false if there is an intersaction)
bool Day::checkIntersaction(Meeting* meet)const
{
	for(int i=0; i<(int)dayMeeting.size() ; ++i)
	{
		if ((*dayMeeting[i]) == *meet)
		{
			return false;
		}
	}

	return true;
}




// DTOR
Day::~Day()
{
}